package com.ruochen.recipe.ui.fragment.order;

import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.blankj.utilcode.util.SizeUtils;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupPosition;
import com.lxj.xpopup.interfaces.OnSelectListener;
import com.lxj.xpopupext.listener.TimePickerListener;
import com.ruochen.common.adapter.RecyclerCommonAdapter;
import com.ruochen.common.adapter.RecyclerViewHolder;
import com.ruochen.common.base.BaseMvpFragment;
import com.ruochen.common.listener.NoDoubleClickListener;
import com.ruochen.recipe.R;
import com.ruochen.recipe.customer.OrderItemDecoration;
import com.ruochen.recipe.customer.SelectTimeDrawerPopup;
import com.ruochen.recipe.databinding.FragmentOrderStateBinding;
import com.ruochen.recipe.mvp.order.OrderStateCovenant;
import com.ruochen.recipe.mvp.order.OrderStatePresenter;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description 订单状态页
 * @Auth RuoChen
 * @Date 13/03/2021, 13:24
 **/
public class OrderStateFragment extends BaseMvpFragment<FragmentOrderStateBinding, OrderStatePresenter> implements OrderStateCovenant.MvpView {

    @Override
    protected void initView(Bundle savedInstanceState) {
        viewBinding.rvOrderList.addItemDecoration(new OrderItemDecoration());
        viewBinding.rvOrderList.setLayoutManager(new LinearLayoutManager(mContext));
        viewBinding.rvOrderList.setAdapter(new RecyclerCommonAdapter<String>(mContext, R.layout.item_order_state,
                Arrays.asList("1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
                        "2", "2", "2", "2", "2", "2", "2", "2", "2",
                        "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2")) {
            @Override
            protected void convert(RecyclerViewHolder holder, String item, int position) {

            }
        });
        viewBinding.tvChangeSelectTime.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View view) {
                new XPopup.Builder(getContext())
                        .hasShadowBg(false)
                        .borderRadius(16)
                        .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
//                        .isDarkTheme(true)
//                        .popupAnimation(PopupAnimation.NoAnimation) //NoAnimation表示禁用动画
//                        .isCenterHorizontal(true) //是否与目标水平居中对齐
//                        .offsetY(-60)
//                        .popupPosition(PopupPosition.Top) //手动指定弹窗的位置
                        .atView(view)
                        .asAttachList(new String[]{"最近1个月订单", "最近3个月订单", "今年内订单", "2020年订单", "2019年订单", "自定义时间段"}, null,
                                new OnSelectListener() {
                                    @Override
                                    public void onSelect(int position, String text) {
                                        if (position == 5) {
                                            showSelectTimeDrawer();
                                        }
                                    }
                                })
                        .show();
            }
        });
    }

    private void showSelectTimeDrawer() {
        Calendar date = Calendar.getInstance();
        date.set(1970, 1, 1);
        Calendar date2 = Calendar.getInstance();
        date2.setTime(new Date());
        SelectTimeDrawerPopup popup = new SelectTimeDrawerPopup(mContext)
                .setDefaultDate(date2)  //设置默认选中日期
                .setDateRang(date, date2) //设置日期范围
                .setItemsVisibleCount(9)
                .setItemTextSize(18)
                .setTimePickerListener(new TimePickerListener() {
                    @Override
                    public void onTimeChanged(Date date) {
                        //时间改变
                    }

                    @Override
                    public void onTimeConfirm(Date date, View view) {

                    }
                });
        new XPopup.Builder(getContext())
                .dismissOnBackPressed(false)
                .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                .popupPosition(PopupPosition.Right)//右边
                .hasStatusBarShadow(true) //启用状态栏阴影
                .asCustom(popup)
                .show();
    }

    @Override
    protected OrderStatePresenter createPresenter() {
        return new OrderStatePresenter(this);
    }

}
